package com.liu.util;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class InetDemo {
    public static void main(String[] args) {
        try {
//            查询本机ip地址
            InetAddress n=InetAddress.getLocalHost();
//            根据域名查询IP地址
            InetAddress nn=InetAddress.getByName("www.baidu.com");
            System.out.println(n);
            System.out.println(nn);
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    }
}
